

import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.*;


/**
 * 
 * 
 *un label ce contine timerul
 */
public class timer2 extends JLabel{
	/**
	 * 
	 * 
	 */

	private static final long serialVersionUID = 1L;
	javax.swing.Timer timer;
	int count = 0;
	public static int minutes;
	public static int seconds;
	public static int hours;
	//public List<String> ora_rules=new ArrayList<String>();
	//public List<String> ora_pref=new ArrayList<String>();
	//public int n=-1;
	//public int i=1;
	//public String temp;
	//public int o=1;
	
	//int go=0,go2=0,go3=0;
	List<Propozitie> Persoane;

	public List<Propozitie> getPersoane() {
		return Persoane;
	}
	public void setPersoane(List<Propozitie> persoane) {
		Persoane = persoane;
	}
	
	/*public void getTimes1(){
	String token = " ";
	String[] lcur;
	String line;

	try{
		BufferedReader in=new BufferedReader(new FileReader("texxt.txt"));
		while((line=in.readLine())!= null){
			lcur=line.split(token);
			for(int j=1;j<lcur.length;j++){
				if(lcur[j].contains(":")){					
					ora_rules.add(lcur[j]);
					i++;
					//continue;
				}}
		}}
	catch(IOException e){
		System.out.println("Error "+ e);
	}
}

public void getTimes2(){
	String token = " ";
	String[] lcur;
	String line;
	int i=1;

	try{
		BufferedReader in=new BufferedReader(new FileReader("preferinte.txt"));
		while((line=in.readLine())!= null){
			lcur=line.split(token);
			for(int j=1;j<lcur.length;j++){
				if(lcur[j].contains(":")){					
					ora_pref.add(lcur[j]);
					i++;
					//continue;
			}}
		}}
		catch(IOException e){
			System.out.println("Error "+ e);
		}
		for(int k=1; k<=ora_pref.size();k++){
			System.out.println(ora_pref.get(k)+" ");
		}
}


	*/		

	/**
	 * 
	 * Verifica in scenariu timpul actiunii si afiseaza subiectul timpul si actiunea ce are loc in timpul respectiv
	 */
	public timer2(List<Propozitie> Persoane) {
		super(" ", SwingConstants.CENTER);
		this.Persoane=Persoane;
		timer = new javax.swing.Timer(10, new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				count++;
				setText(getStringTime(count));
				//getTimes1();
				
				//if (timer2.minutes==1) System.out.println(" merge");
				int go=0,go2=0,go3=0;
				/*for(int k=0; k<ora_rules.size();k++){				
				String[] currentHour = ora_rules.get(k).split(":");
				if ((timer2.hours==Integer.parseInt(currentHour[0]))&&
						(timer2.minutes==Integer.parseInt(currentHour[1]))&&
						(timer2.seconds==Integer.parseInt(currentHour[2]))){
					try{
						BufferedReader nn=new BufferedReader(new FileReader("texxt.txt"));
						
						while(n<=k){							
							temp=nn.readLine();
							System.out.println(temp);
							n++;
						}
					}
					catch(IOException e){
						System.out.println("Error "+ e);}

				}
			}*/
					
				
				//System.out.println(getPersoane());
				for(int i=5;i<getPersoane().size();i++){				
					go=Integer.parseInt(getPersoane().get(i).getOraStart());				
					go2=Integer.parseInt(getPersoane().get(i).getMinStart());
					go3=Integer.parseInt(getPersoane().get(i).getSecStart());
					if ((timer2.hours==go)&&(timer2.minutes==go2)&&(timer2.seconds==go3)){ 
						System.out.print(getPersoane().get(i).getPersoana()+" ");
						System.out.print(getPersoane().get(i).getActiune()+" ");
						//System.out.print(getPersoane().get(i).getPLocation()+" ");
						System.out.print(getPersoane().get(i).getLocation()+" ");
						System.out.print(getPersoane().get(i).getOraStart()+":");
						System.out.print(getPersoane().get(i).getMinStart()+":");
						System.out.print(getPersoane().get(i).getSecStart()+" ");
						System.out.print(getPersoane().get(i).getOraEnd()+":");
						System.out.print(getPersoane().get(i).getMinEnd()+":");
						System.out.print(getPersoane().get(i).getSecEnd()+" ");
						System.out.println();}
				}
			}
		});
	}
	/**
	 * 
	 * @param sec numarul de secunde initial
	 * @return
	 * timerul in format decimal
	 */
	public static final String getStringTime(int sec) {
		seconds = sec;
		minutes = (int)(seconds/60);
		hours = (int)(minutes/60);
		minutes -= hours*60;
		seconds -= (hours*3600)+(minutes*60);
		return(((hours<10)?"0"+hours:""+hours)+":"+((minutes<10)?"0"+minutes:""+minutes)+":"+((seconds<10)?"0"+seconds:""+seconds));
	}
	/**
	 * 
	 *metoda ce porneste timerul
	 */
	public void start() {
		count = 0;
		setText(getStringTime(count));
		timer.setInitialDelay(1000);
		timer.start();
	}
	/**
	 * 
	 * opreste timerul
	 * @return 
	 * timpul la care s-a oprit timerul
	 */
	public long stop() {
		timer.stop();
		return(count);
	}}




	